<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <title>欢迎页面-X-admin2.2</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="../../static/css/font.css">
        <link rel="stylesheet" href="../../static/css/xadmin.css">
        <script src="../../static/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="../../static/js/xadmin.js"></script>
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
        <div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="#">首页</a>
            <a href="#">s3管理</a>
            <a>
              <cite>对象管理</cite></a>
          </span>
          <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <form class="layui-form layui-col-space5">
                                <div class="layui-input-inline layui-show-xs-block">
                                    <select name="account" lay-filter="account" id="account" required="" lay-verify="required">
                                    </select>
                                </div>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <select name="bucket" lay-filter="bucket" id="bucket" required="" lay-verify="required">
                                    </select>
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <button class="layui-btn"  lay-submit="" lay-filter="search"><i class="layui-icon">&#xe615;</i></button>
                                </div>
                            </form>
                        </div>
                        <div class="layui-card-header">
                            <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
                            <button class="layui-btn" onclick="xadmin.open('上传文件','/BucketUpload/',400,600)"><i class="layui-icon"></i>上传</button>
                        </div>

                        <div class="layui-card-body " id="objects" lay-filter="objects" lay-data="{id: 'objects'}">

                        </div>
                    </div>
                </div>
            </div>
        </div> 
    </body>
    <script>
      layui.use(['table', 'form'], function() {
          let table = layui.table;
          let form = layui.form;

          $.ajax({
                  type: 'post',
                  url: '/AwsAccount/',
                  dataType: 'json',
                  success: function(res){
                      let data = res.data;
                      $('#account').append('<option value="" selected="true" disabled="disabled">---请选择账号---</option>');
                      $.each(data, function (index, item) {
                        $('#account').append('<option value="'+item.name+'">'+item.name+'</option>')
                      });
                      form.render();
                  }
          });

          form.on('select(account)', function (data) {
              var index = layer.load(1);
              $.ajax({
                  type: 'post',
                  url: '/Bucket/',
                  data: {'account': $('#account').val()},
                  dataType: 'json',
                  success: function(res){
                      layer.close(index);
                      let data = res.data;
                      $('#bucket').empty();
                      $('#bucket').append('<option value="" selected="true" disabled="disabled">---请选择bucket---</option>');
                      $.each(data, function (index, item) {
                        $('#bucket').append('<option value="'+item.name+'">'+item.name+'</option>')
                      });
                      form.render();
                  }
                });
          });

          form.on('submit(search)', function (data) {
            table.reload('objects',{
                url: '/BucketManage/',
                where: {account: $('#account').val(), bucket: $('#bucket').val()},
                page: {
                    curr: 1
                },
                loading: true
            });
            return false;
          });
          table.render({
              elem: '#objects'
              , height: 600
              , url: '' //数据接口
              , method: 'post'  //
              , page: true //开启分页
              , cols: [[ //表头
                  {checkbox: true}
                  , {field: 'object', title: 'Object'}
                  , {field: 'size', title: '大小'}
                  , {field: 'last_modified', title: '上次修改时间'}
                  , {fixed: 'right', title: '操作', align: 'center', width: '12%', toolbar: '#bar'}
              ]]
          });

      });

    </script>
    <script type="text/html" id="bar">
        <a class="layui-btn layui-btn-xs" lay-event="download">下载</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>

    </script>
</html>